<script>
    function submit_buy_now() {

        if (! $('input[name=addressId]').val())
        {
            alert('请填写收货地址');
            return false;
        }

        var oRadioVal = $('input:radio[name="deliverId"]:checked').val();
        if (!oRadioVal) {
            alert('请选择快递方式');
            return false;
        }

        var oRadioVal = $('input:radio[name="paymentId"]:checked').val();
        if (!oRadioVal) {
            alert('请选择支付方式');
            return false;
        }

        return true;
 
    }

    // 发票动作响应(重置发票组得状态)
    function invoice_reset_stats ()
    {
        var iType = $('select[name="invoiceType"]').val();
        if (iType <= 0)
        {
            $('.order-invoiceContent').hide();
            $('.order-invoiceTitle').hide();
        }
        else
        {
            $('.order-invoiceContent').show();
            $('.order-invoiceTitle').show();
        }
    }

    // 快递方式改变响应
    function deliver_config_changed (item)
    {
        order_rebuild_money();
    }

    // 重新计算订单价格
    function order_rebuild_money ()
    {
        var moneyGoods  = <{$money.goods}>;
        var moneyTicket = <{$money.ticket}>;
        var moneyCoins  = <{$money.coin}>;
        var moneyDeliver= parseInt($('input[name="deliverId"]:checked').attr('money'));
        var money1 = moneyGoods + moneyDeliver - moneyTicket;

        if ($('input[name="coinMoney"]').is(':checked'))
        {
            if (moneyCoins >= money1)
                moneyCoins = money1;

       }
        else
        {
            moneyCoins = 0;
        }


        moneyTotal = moneyGoods + moneyDeliver - moneyTicket - moneyCoins;
        moneyTotalYuan = moneyTotal / 100;
        moneyCoinsYuan = moneyCoins / 100;
        moneyDelivYuan = moneyDeliver / 100;

        $('.coinCostMoney').html  ('￥' + moneyCoinsYuan.toFixed(2));
        $('.deliverMoney').html   ('￥' + moneyDelivYuan.toFixed(2));
        $('.orderTotalMoney').html('￥' + moneyTotalYuan.toFixed(2));
    }

    // 页面初始化
    $(document).ready(function () {

        // 发票动作响应
        invoice_reset_stats ();
        $('select[name="invoiceType"]').change(invoice_reset_stats);

        // 快递动作响应
        $('input[name="deliverId"]').click(function () {
            deliver_config_changed(this);
        });

        var dItem = $('input[name="deliverId"]').get(0);
        $(dItem).attr('checked', 'checked');
        deliver_config_changed(dItem);

        $('input[name="coinMoney"]').change(function () {
            order_rebuild_money();
        });

    });
</script>
